<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
#r-result{height:25px;;width:100%;float:left;}
#l-map{height:90%;width:100%;float:left;border-right:2px solid #bcbcbc;}

</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=175c2f620d20964e0e7ba7c51f2b73a8"></script>
<script src="../jquery/jquery-1.5.2.min.js" type="text/javascript"></script>
<title>鼠标点击拾取坐标</title>
<script type="text/javascript">
var coord="";
function load_coord()
{
var url = location.search;
url = url.replace("?",""); 
coord=url.split("=")[1]; 
}
load_coord();
</script>
</head>
<body>
<div id="r-result">
    请输入:<input type="text" id="suggestId" size="20" value="" style="width:250px;" />
 <input type="button" onclick="deleteMarker()" value="删除标注" />
 </div><div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display: none;">
</div>
<div id="l-map"></div>
</body>
</html>
<script type="text/javascript">
var map = new BMap.Map("l-map");
map.centerAndZoom("苏州",12);                   // 初始化地图,设置城市和地图级别。
map.enableScrollWheelZoom();                            //启用滚轮放大缩小
var tempmarker=null;
map.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_HYBRID_MAP]}));     //2D图，卫星图
map.addControl(new BMap.MapTypeControl({anchor: BMAP_ANCHOR_TOP_LEFT}));    //左上角，默认地图控件
if(coord.length>0){
	 
	tempmarker = new BMap.Marker(new BMap.Point(coord.split(",")[0],coord.split(",")[1]));  // 创建标注
	map.addOverlay(tempmarker); 
	  var infoWindow1 = new BMap.InfoWindow("当前坐标:"+ coord.split(",")[0]+","+coord.split(",")[1]);
	  tempmarker.addEventListener("mouseover", function(){this.openInfoWindow(infoWindow1);});
	  $('#tempdata987654321', parent.document).html(coord.split(",")[0]+","+coord.split(",")[1]);
}else{
	$('#tempdata987654321', parent.document).html("");
}
function G(id) {
    return document.getElementById(id);
}
var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
	    {"input" : "suggestId"
	    ,"location" : map
	});

ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
	var str = "";
	    var _value = e.fromitem.value;
	    var value = "";
	    if (e.fromitem.index > -1) {
	        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
	    }    
	    str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
	    value = "";
	    if (e.toitem.index > -1) {
	        _value = e.toitem.value;
	        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
	    }    
	    str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
	    G("searchResultPanel").innerHTML = str;
	});
	var myValue;
	ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
	var _value = e.item.value;
	    myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
	    G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
	    setPlace();
	});

	function setPlace(){
	    map.clearOverlays();    //清除地图上所有覆盖物
	    function myFun(){
	        var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
	        map.centerAndZoom(pp, 18);
	        tempmarker = new BMap.Marker(pp);
	        map.addOverlay(tempmarker);    //添加标注
	        $('#tempdata987654321', parent.document).html(pp.lng+","+pp.lat);
	        var infoWindow1 = new BMap.InfoWindow("当前坐标:"+pp.lng+","+pp.lat);
	        tempmarker.addEventListener("mouseover", function(){this.openInfoWindow(infoWindow1);});
	    }
	    var local = new BMap.LocalSearch(map, { //智能搜索
	      onSearchComplete: myFun
	    });
	    local.search(myValue);
	}
function deleteMarker(){
    map.removeOverlay(tempmarker);
    tempmarker=null;
}
map.addEventListener("click", function(e){
 // document.getElementById("r-result").innerHTML = e.point.lng + ", " + e.point.lat;
    if(tempmarker){
        deleteMarker();
    }
    tempmarker = new BMap.Marker(new BMap.Point(e.point.lng, e.point.lat));  // 创建标注
    map.addOverlay(tempmarker);
    var infoWindow1 = new BMap.InfoWindow("当前坐标:"+ e.point.lng+","+e.point.lat);
    tempmarker.addEventListener("mouseover", function(){this.openInfoWindow(infoWindow1);});
    $('#tempdata987654321', parent.document).html(e.point.lng+","+e.point.lat);
});
</script>
